//
//  ST_IgnoreModelViewController.swift
//  btvideo
//
//  Created by mac on 2020/8/7.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit

class ST_IgnoreModelViewController: ST_BTLightBarViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
         
        
        title_nav_btn.setTitleForAllStates("忽略的遇见")
        
        view.addSubview(segment_control)
        segment_control.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalToSuperview().inset(44+statusBarHeight)
            make.height.equalTo(ST_MeetYouSegmentControl.height)
        }
        
        
        segment_control.selected_closure = {[weak self] idx in
            self?.scrollView.setContentOffset(CGPoint.init(x: ScreenWidth*idx.cgFloat, y: 0), animated: true)
        }
        
        
        view.addSubview(scrollView)
        scrollView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(segment_control.snp.bottom)
        }
        
        scrollView.addSubview(contentView)
        contentView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
            make.width.equalToSuperview().dividedBy(0.5)
            make.height.equalToSuperview()
        }
        
        self.addChild(love_me_controller)
        contentView.addSubview(love_me_controller.view)
        love_me_controller.view.snp.makeConstraints { (make) in
            make.width.equalTo(ScreenWidth)
            make.left.top.bottom.equalToSuperview()
        }
        
        
        self.addChild(look_me_controller)
        contentView.addSubview(look_me_controller.view)
        look_me_controller.view.snp.makeConstraints { (make) in
            make.width.equalTo(ScreenWidth)
            make.right.top.bottom.equalToSuperview()
        }
    }
    
//    MARK: - Properties
    fileprivate lazy var scrollView:UIScrollView = {
       let control = UIScrollView()
        control.delegate = self
        control.isPagingEnabled = true
        if #available(iOS 11.0, *) {
            control.contentInsetAdjustmentBehavior = .never
        }
        control.showsVerticalScrollIndicator = false
        control.showsHorizontalScrollIndicator = false
        
        return control
    }()
    
    fileprivate lazy var contentView:UIView = {
       let control = UIView()
        return control
    }()
    
    
    fileprivate lazy var love_me_controller:ST_IgnoreLoveViewController = {
       let control = ST_IgnoreLoveViewController()
        return control
    }()
    
    fileprivate lazy var look_me_controller:ST_IgnoreLookViewController = {
       let control = ST_IgnoreLookViewController()
        return control
    }()
    
    
    fileprivate lazy var segment_control:ST_MeetYouSegmentControl = {
       let control = ST_MeetYouSegmentControl()
        control.titleArray = ["忽略喜欢","忽略看过"]
        return control
    }()

}

extension ST_IgnoreModelViewController:UIScrollViewDelegate{
    
    func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
                
        
        if !decelerate{
                scrollviewdidEndScroll(scrollView)
        }
    }
    
    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        
            scrollviewdidEndScroll(scrollView)
        
    }
    
    
//    MARK: 停止滚动
    func scrollviewdidEndScroll(_ scrollView:UIScrollView){
        
        let currPage = (scrollView.contentOffset.x/ScreenWidth).int
        
        self.segment_control.selectBtn(index: currPage)
        
    }
    
}
